<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>预约</title>
</head>
<link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css">
<link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.min.css">

<link rel="stylesheet" href="../../src/dist/css/page.css">

<body>
<div class="weui-cells user-binding">
    <div class="weui-cells__tips">用户信息页</div>
    <div class="weui-cell">
        <div class="weui-cell__hd">
            <i class="iconfont iconyonghuming"></i>
        </div>
        <div class="weui-cell__bd">
            <p>用户号</p>
        </div>

        <div class="weui-cell__bd">
            <input class="weui-input" type="number" pattern="[0-9]*" placeholder="请输入用户账号" id="PartyCode">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd">
            <i class="iconfont iconleixing"></i>
        </div>
        <div class="weui-cell__bd">
            <p>安检类型</p>
        </div>

        <div class="weui-cell__bd">
            <input class="weui-input" type="text" placeholder="类型" id="Type">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd">
            <i class="iconfont iconshijian"></i>
        </div>
        <div class="weui-cell__bd">
            <p>预约时间</p>
        </div>

        <div class="weui-cell__bd">
            <input class="weui-input" type="text"  placeholder="请选择预约时间" id="ApplyDate">
        </div>
    </div>
    <div class="button_sp_area">
        <a href="javascript:;" class="weui-btn weui-btn_primary" onclick="binDingAction()">预约</a>
    </div>
</div>

<script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/jquery-weui.min.js"></script>

<!-- Dist -->
<script src="../../src/dist/js/index.js"></script>
<script src="../../src/dist/js/utils.js"></script>
<script src="../../src/dist/js/request.js"></script>
<script>
    var customid = '';
    $(function(){
        var paras = location.search;            //search获得地址中的参数，内容为'?itemId=12'
        var result = paras.match(/[^\?&]*=[^&]*/g);     //match是字符串中符合的字段一个一个取出来，result中的值为['login=xx','table=admin']
        paras = {};                    //让paras变成没有内容的json对象
        for (i in result) {
            var temp = result[i].split('=');    //split()将一个字符串分解成一个数组,两次遍历result中的值分别为['itemId','xx']
            paras[temp[0]] = temp[1];
        }
        customid = paras.customid;     //根据参数名"itemId"，获取参数值

        $("#PartyCode").val(customid)
        $("#ApplyDate").datetimePicker();
        $("#Type").select({
            title: "安检类型",
            items: [
                {
                    title: "安检",
                    value: "0",
                },
                {
                    title: "点火",
                    value: "1",
                }
            ]
        });
    })


    function binDingAction(){
      let PartyCode = $("#PartyCode").val()
        let ApplyDate = $("#ApplyDate").val()
        let Type=$("#Type").val()
      if(PartyCode === ''){
         $.toast("用户号不能为空", "text")
        return
      }
        var reg = /^\d{10}$/
        if (!reg.test(PartyCode)) {
			$.toast("用户号格式不正确", "text");
            return false
        }
        if(ApplyDate === ''){
            $.toast("请选择预约时间", "text")
            return
        }
        if(Type === ''){
            $.toast("请选择预约类型", "text")
            return
        }

       /* get("/wechat/binding/saveBinding?openid=" + openid + '&usercode='+ usercode, {}, function (data) {
            if (data.code === 0) {
                location.href = './bangdingList.html'
            } else {
                $.toast('绑定失败!', 'forbidden');
            }
        }, false, true);*/
        $.ajax({
            type: "POST",
            url: CJINGdataLink+"/Controllers/CustomerServiceCenter/SecurityCheck/OfficialApplicationHandler.ashx",
            data: {
                cmd: " save ",
                JsonData: JSON.stringify( {PartyCode :PartyCode, Type :Type, ApplyDate :ApplyDate })
            },
            success: function (data) {
            var result = JSON.parse(data);
            if (result.code === "0") {
                $.toast("保存成功", 'forbidden');
                location.href = './list.html'
            }else{//失败    result.msg为错误信息
                $.toast(result.msg, 'forbidden');
            }
        },
        error: function (data) {

        }
    })


    }
</script>
</body>
</html>
